#!/usr/bin/make -f

DEBVERS := $(shell dpkg-parsechangelog | sed -n -e 's/^Version: //p')
VERSION := $(shell echo '$(DEBVERS)' | sed -e 's/^[[:digit:]]*://' -e 's/[~-].*//')

build: clean build-stamp libraries binary post-clean

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	dh_clean

build-stamp:
	touch build-stamp

libraries:
	cp ../../builds/current/libschimpf-sys_current.jar debian/input/libschimpf-sys.jar

binary:
	dh_testdir
	dh_testroot
	dh_prep
	dh_install
	dh_installchangelogs
	dh_icons
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

post-clean:
	dh_clean
	rm -f build-stamp
	rm -Rf debian/input/*
	chown hschimpf:root ../libschimpf-sys_$(VERSION)_all.deb
	mv ../libschimpf-sys_$(VERSION)_all.deb ../../builds/$(VERSION)/libschimpf-sys_$(VERSION)_all.deb
	rm -f ../../builds/current/libschimpf-sys_current_all.deb
	ln -s "`dirname ../../builds/$(VERSION)/libschimpf-sys_$(VERSION)_all.deb`"/libschimpf-sys_$(VERSION)_all.deb ../../builds/current/libschimpf-sys_current_all.deb